/**
 * @file    drv_spi.h
 * @brief   SPI底层驱动
 * @author  Liuwei
 * @version 1.0.1
 * @date    2023-04-17
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-04-17 <td>1.0.1     <td>Liuwei   <td>首次创建
 * </table>
 */

#ifndef __DRV_SPI_H_
#define __DRV_SPI_H_

/* File Includes -------------------------------------------------------------*/
#include <stdint.h>
#include "drv_gpio.h"
#include "drv_mcu.h"
/* Cplusplus -----------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif

/* Macro/Define/Typedef ------------------------------------------------------*/
#define SPI_USE_SOFT

#ifdef SPI_USE_SOFT
	#define drv_spi_clk_set_high()        drv_gpio_set_pin(AFE_SPI_CLK_PORT , AFE_SPI_CLK_PIN)     
	#define drv_spi_clk_set_low()         drv_gpio_reset_pin(AFE_SPI_CLK_PORT , AFE_SPI_CLK_PIN)
	#define drv_spi_miso_read()       	  drv_gpio_read_pin(AFE_SPI_MISO_PORT , AFE_SPI_MISO_PIN)
	#define drv_spi_mosi_set_high()       drv_gpio_set_pin(AFE_SPI_MOSI_PORT , AFE_SPI_MOSI_PIN)
	#define drv_spi_mosi_set_low()        drv_gpio_reset_pin(AFE_SPI_MOSI_PORT , AFE_SPI_MOSI_PIN)
	#define drv_spi_cs_set_high()         drv_gpio_set_pin(AFE_SPI_CS_PORT , AFE_SPI_CS_PIN);
	#define drv_spi_cs_set_low()          drv_gpio_reset_pin(AFE_SPI_CS_PORT , AFE_SPI_CS_PIN);
	#define spi_delay()         	      mcu_delay_us(10) 
#endif

/**
 * @brief SPI 编号定义
 */
enum
{
	DRV_SPI0 ,
	DRV_SPI1 ,
	DRV_SPI2 ,
};

/* @brief */

/* Variables -----------------------------------------------------------------*/

/*******************************************************************************
* define Interface module
*
*//*! @addtogroup API LIST 
*******************************************************************************/
void drv_spi_init(uint8_t spi_id);
uint8_t drv_spi_write_byte(uint8_t spi_id ,uint8_t wr_byte);
uint8_t drv_spi_write_data(uint8_t spi_id ,uint8_t *wr_buf , uint16_t wr_num);
uint8_t drv_spi_read_data(uint8_t spi_id ,uint8_t *rd_buf , uint16_t rd_num);
uint8_t drv_spi_write_read_data(uint8_t spi_id , uint8_t *wbuf ,uint8_t *rbuf ,uint32_t size);

void drv_spi_soft_init(void);
void drv_spi_soft_send_bytes(uint8_t *send_buff, uint16_t data_size);
void drv_spi_soft_send_recv_bytes(uint8_t *send_buff, uint8_t *recv_buff, uint16_t data_size);

uint8_t spi_drv_miso_read(void);
/*! @} End of Interface API List */

#ifdef __cplusplus
}
#endif

#endif  /* #ifndef __DRV_SPI_H_ */
/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/
